<?php

require_once 'common/conn.php';

if (isset($_GET['lastID'])) {
    $lastID = $_GET['lastID'];
} else {
    $lastID = 0;
}
if (isset($_GET['count'])) {
    $count = $_GET['count'];
}

$data = array();
if (isset($_GET['flashcode']) && $_GET['flashcode'] != "[]") {
    $db = new DBC();
    $flashcode = $_GET['flashcode'];
    $products = json_decode($flashcode, true);
    $codes = "";
    foreach ($products as $pro) {
        $codes = $codes . "," . $pro['flashcode'];
    }
    if (strlen($codes) > 0) {
        if (substr($codes, 0, 1) == ',') {
            $codes = substr($codes, 1, strlen($codes));
        }
    }
    $sql = "SELECT productid,flashcode,age,name,url,imageURL,version,size,type1,type2,downloadtimes FROM t_product WHERE status = 1 AND flashcode NOT IN ('" . $codes . "') AND productid > " . $lastID . " ORDER BY productid LIMIT 0," . $count;
} else {
    $sql = "SELECT productid,flashcode,age,name,url,imageURL,version,size,type1,type2,downloadtimes FROM t_product WHERE status = 1 AND productid > " . $lastID . " ORDER BY productid LIMIT 0," . $count;
}

$db = new DBC();
$data = $db->fetchData($sql);
echo json_encode($data);
?>